import React, { Fragment, useContext } from "react";
import { MyContext } from "./MyContext";

function Item1(props) {
    const { num, setNum } = useContext(MyContext);
    const increment = () => {
        setNum(num => num += 1);
    }
    const decrement = () => {
        setNum(num => num -= 1);
    }
    return (
        <Fragment>
            <div className="mt-3 alert alert-primary">
                当前值为：{num}
            </div>
            <div onClick={increment} className="btn-sm btn btn-warning">增加+1</div>
            <div onClick={decrement} className="ml-3 btn-sm btn btn-danger">减少-1</div>
        </Fragment>
    )
}

export default Item1